{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0886dc53",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccc4420b",
   "metadata": {},
   "source": [
    "## 纵向拼接DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ea8f2132",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = pd.DataFrame({\n",
    "    '商品名': ['iPhone 12', 'MacBook Air', 'iPad', 'Apple Watch Series 6'],\n",
    "    '单价（元）': [6799, 8499, 3199, 2699],\n",
    "    '颜色': ['蓝色', '金色', '灰色', '粉色'],\n",
    "    '库存数量': [100, 50, 150, 80]\n",
    "})\n",
    "\n",
    "\n",
    "df2 = pd.DataFrame({\n",
    "    '商品名': ['AirPods Pro', 'HomePod mini', 'Apple TV 4K', 'Beats Flex'],\n",
    "    '单价（元）': [1599, 749, 1499, 399],\n",
    "    '颜色': ['白色', '空间灰色', '黑色', '黄色'],\n",
    "    '库存数量': [120, 80, 60, 200]\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ecdc7cbe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价（元）</th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>iPhone 12</td>\n",
       "      <td>6799</td>\n",
       "      <td>蓝色</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MacBook Air</td>\n",
       "      <td>8499</td>\n",
       "      <td>金色</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>iPad</td>\n",
       "      <td>3199</td>\n",
       "      <td>灰色</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple Watch Series 6</td>\n",
       "      <td>2699</td>\n",
       "      <td>粉色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    商品名  单价（元）  颜色  库存数量\n",
       "0             iPhone 12   6799  蓝色   100\n",
       "1           MacBook Air   8499  金色    50\n",
       "2                  iPad   3199  灰色   150\n",
       "3  Apple Watch Series 6   2699  粉色    80"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "8119a43f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价（元）</th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AirPods Pro</td>\n",
       "      <td>1599</td>\n",
       "      <td>白色</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HomePod mini</td>\n",
       "      <td>749</td>\n",
       "      <td>空间灰色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Apple TV 4K</td>\n",
       "      <td>1499</td>\n",
       "      <td>黑色</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Beats Flex</td>\n",
       "      <td>399</td>\n",
       "      <td>黄色</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            商品名  单价（元）    颜色  库存数量\n",
       "0   AirPods Pro   1599    白色   120\n",
       "1  HomePod mini    749  空间灰色    80\n",
       "2   Apple TV 4K   1499    黑色    60\n",
       "3    Beats Flex    399    黄色   200"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "5e76e30a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价（元）</th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>iPhone 12</td>\n",
       "      <td>6799</td>\n",
       "      <td>蓝色</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MacBook Air</td>\n",
       "      <td>8499</td>\n",
       "      <td>金色</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>iPad</td>\n",
       "      <td>3199</td>\n",
       "      <td>灰色</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple Watch Series 6</td>\n",
       "      <td>2699</td>\n",
       "      <td>粉色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AirPods Pro</td>\n",
       "      <td>1599</td>\n",
       "      <td>白色</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HomePod mini</td>\n",
       "      <td>749</td>\n",
       "      <td>空间灰色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Apple TV 4K</td>\n",
       "      <td>1499</td>\n",
       "      <td>黑色</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Beats Flex</td>\n",
       "      <td>399</td>\n",
       "      <td>黄色</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    商品名  单价（元）    颜色  库存数量\n",
       "0             iPhone 12   6799    蓝色   100\n",
       "1           MacBook Air   8499    金色    50\n",
       "2                  iPad   3199    灰色   150\n",
       "3  Apple Watch Series 6   2699    粉色    80\n",
       "0           AirPods Pro   1599    白色   120\n",
       "1          HomePod mini    749  空间灰色    80\n",
       "2           Apple TV 4K   1499    黑色    60\n",
       "3            Beats Flex    399    黄色   200"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 纵向拼接df1和df2\n",
    "pd.concat([df1, df2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "4fa6b518",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价（元）</th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>iPhone 12</td>\n",
       "      <td>6799</td>\n",
       "      <td>蓝色</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MacBook Air</td>\n",
       "      <td>8499</td>\n",
       "      <td>金色</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>iPad</td>\n",
       "      <td>3199</td>\n",
       "      <td>灰色</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple Watch Series 6</td>\n",
       "      <td>2699</td>\n",
       "      <td>粉色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AirPods Pro</td>\n",
       "      <td>1599</td>\n",
       "      <td>白色</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>HomePod mini</td>\n",
       "      <td>749</td>\n",
       "      <td>空间灰色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Apple TV 4K</td>\n",
       "      <td>1499</td>\n",
       "      <td>黑色</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Beats Flex</td>\n",
       "      <td>399</td>\n",
       "      <td>黄色</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    商品名  单价（元）    颜色  库存数量\n",
       "0             iPhone 12   6799    蓝色   100\n",
       "1           MacBook Air   8499    金色    50\n",
       "2                  iPad   3199    灰色   150\n",
       "3  Apple Watch Series 6   2699    粉色    80\n",
       "4           AirPods Pro   1599    白色   120\n",
       "5          HomePod mini    749  空间灰色    80\n",
       "6           Apple TV 4K   1499    黑色    60\n",
       "7            Beats Flex    399    黄色   200"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 纵向拼接df1和df2（忽略索引）\n",
    "pd.concat([df1, df2], ignore_index = True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2e77f090",
   "metadata": {},
   "outputs": [],
   "source": [
    "df3 = pd.DataFrame({\n",
    "    '商品名': ['iPhone 12', 'MacBook Air', 'iPad', 'Apple Watch Series 6'],\n",
    "    '单价（元）': [6799, 8499, 3199, 2699],\n",
    "    '颜色': ['蓝色', '金色', '灰色', '粉色'],\n",
    "    '库存数量': [100, 50, 150, 80]\n",
    "})\n",
    "\n",
    "\n",
    "df4 = pd.DataFrame({\n",
    "    '商品名': ['AirPods Pro', 'HomePod mini', 'Apple TV 4K', 'Beats Flex'],\n",
    "    '单价': [1599, 749, 1499, 399],\n",
    "    '颜色': ['白色', '空间灰色', '黑色', '黄色'],\n",
    "    '库存数量': [120, 80, 60, 200]\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "3da301d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价（元）</th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>iPhone 12</td>\n",
       "      <td>6799</td>\n",
       "      <td>蓝色</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MacBook Air</td>\n",
       "      <td>8499</td>\n",
       "      <td>金色</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>iPad</td>\n",
       "      <td>3199</td>\n",
       "      <td>灰色</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple Watch Series 6</td>\n",
       "      <td>2699</td>\n",
       "      <td>粉色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    商品名  单价（元）  颜色  库存数量\n",
       "0             iPhone 12   6799  蓝色   100\n",
       "1           MacBook Air   8499  金色    50\n",
       "2                  iPad   3199  灰色   150\n",
       "3  Apple Watch Series 6   2699  粉色    80"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "074f5e35",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价</th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>AirPods Pro</td>\n",
       "      <td>1599</td>\n",
       "      <td>白色</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>HomePod mini</td>\n",
       "      <td>749</td>\n",
       "      <td>空间灰色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Apple TV 4K</td>\n",
       "      <td>1499</td>\n",
       "      <td>黑色</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Beats Flex</td>\n",
       "      <td>399</td>\n",
       "      <td>黄色</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            商品名    单价    颜色  库存数量\n",
       "0   AirPods Pro  1599    白色   120\n",
       "1  HomePod mini   749  空间灰色    80\n",
       "2   Apple TV 4K  1499    黑色    60\n",
       "3    Beats Flex   399    黄色   200"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c8455490",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价（元）</th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "      <th>单价</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>iPhone 12</td>\n",
       "      <td>6799.0</td>\n",
       "      <td>蓝色</td>\n",
       "      <td>100</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MacBook Air</td>\n",
       "      <td>8499.0</td>\n",
       "      <td>金色</td>\n",
       "      <td>50</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>iPad</td>\n",
       "      <td>3199.0</td>\n",
       "      <td>灰色</td>\n",
       "      <td>150</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple Watch Series 6</td>\n",
       "      <td>2699.0</td>\n",
       "      <td>粉色</td>\n",
       "      <td>80</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>AirPods Pro</td>\n",
       "      <td>NaN</td>\n",
       "      <td>白色</td>\n",
       "      <td>120</td>\n",
       "      <td>1599.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>HomePod mini</td>\n",
       "      <td>NaN</td>\n",
       "      <td>空间灰色</td>\n",
       "      <td>80</td>\n",
       "      <td>749.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Apple TV 4K</td>\n",
       "      <td>NaN</td>\n",
       "      <td>黑色</td>\n",
       "      <td>60</td>\n",
       "      <td>1499.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Beats Flex</td>\n",
       "      <td>NaN</td>\n",
       "      <td>黄色</td>\n",
       "      <td>200</td>\n",
       "      <td>399.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    商品名   单价（元）    颜色  库存数量      单价\n",
       "0             iPhone 12  6799.0    蓝色   100     NaN\n",
       "1           MacBook Air  8499.0    金色    50     NaN\n",
       "2                  iPad  3199.0    灰色   150     NaN\n",
       "3  Apple Watch Series 6  2699.0    粉色    80     NaN\n",
       "4           AirPods Pro     NaN    白色   120  1599.0\n",
       "5          HomePod mini     NaN  空间灰色    80   749.0\n",
       "6           Apple TV 4K     NaN    黑色    60  1499.0\n",
       "7            Beats Flex     NaN    黄色   200   399.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 纵向拼接df3和df4（忽略索引）\n",
    "pd.concat([df3, df4], ignore_index = True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99f4abab",
   "metadata": {},
   "source": [
    "## 横向拼接DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a81f19e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "df5 = pd.DataFrame({\n",
    "    '商品名': ['iPhone 12', 'MacBook Air', 'iPad', 'Apple Watch Series 6'],\n",
    "    '单价（元）': [6799, 8499, 3199, 2699]\n",
    "})\n",
    "\n",
    "\n",
    "df6 = pd.DataFrame({\n",
    "    '颜色': ['蓝色', '金色', '灰色', '粉色'],\n",
    "    '库存数量': [100, 50, 150, 80]\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "2d7ce904",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价（元）</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>iPhone 12</td>\n",
       "      <td>6799</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MacBook Air</td>\n",
       "      <td>8499</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>iPad</td>\n",
       "      <td>3199</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple Watch Series 6</td>\n",
       "      <td>2699</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    商品名  单价（元）\n",
       "0             iPhone 12   6799\n",
       "1           MacBook Air   8499\n",
       "2                  iPad   3199\n",
       "3  Apple Watch Series 6   2699"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "97baa3c3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>蓝色</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>金色</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>灰色</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>粉色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   颜色  库存数量\n",
       "0  蓝色   100\n",
       "1  金色    50\n",
       "2  灰色   150\n",
       "3  粉色    80"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "748a225e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价（元）</th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "      <th>商品名</th>\n",
       "      <th>单价</th>\n",
       "      <th>颜色</th>\n",
       "      <th>库存数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>iPhone 12</td>\n",
       "      <td>6799</td>\n",
       "      <td>蓝色</td>\n",
       "      <td>100</td>\n",
       "      <td>AirPods Pro</td>\n",
       "      <td>1599</td>\n",
       "      <td>白色</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>MacBook Air</td>\n",
       "      <td>8499</td>\n",
       "      <td>金色</td>\n",
       "      <td>50</td>\n",
       "      <td>HomePod mini</td>\n",
       "      <td>749</td>\n",
       "      <td>空间灰色</td>\n",
       "      <td>80</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>iPad</td>\n",
       "      <td>3199</td>\n",
       "      <td>灰色</td>\n",
       "      <td>150</td>\n",
       "      <td>Apple TV 4K</td>\n",
       "      <td>1499</td>\n",
       "      <td>黑色</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Apple Watch Series 6</td>\n",
       "      <td>2699</td>\n",
       "      <td>粉色</td>\n",
       "      <td>80</td>\n",
       "      <td>Beats Flex</td>\n",
       "      <td>399</td>\n",
       "      <td>黄色</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    商品名  单价（元）  颜色  库存数量           商品名    单价    颜色  库存数量\n",
       "0             iPhone 12   6799  蓝色   100   AirPods Pro  1599    白色   120\n",
       "1           MacBook Air   8499  金色    50  HomePod mini   749  空间灰色    80\n",
       "2                  iPad   3199  灰色   150   Apple TV 4K  1499    黑色    60\n",
       "3  Apple Watch Series 6   2699  粉色    80    Beats Flex   399    黄色   200"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 横向拼接df3和df4\n",
    "pd.concat([df3, df4], axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "950590dc",
   "metadata": {},
   "source": [
    "## 合并DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "f5681c96",
   "metadata": {},
   "outputs": [],
   "source": [
    "customer_df = pd.DataFrame({\n",
    "    '客户ID': [1, 2, 3, 4],\n",
    "    '姓名': ['Amy', 'Bill', 'Cathy', 'Dave'],\n",
    "    '邮箱': ['amy@xxx.com', 'bill@xxx.com', 'cat@xxx.com', 'dave@xxx.com']\n",
    "})\n",
    "\n",
    "order_df = pd.DataFrame({\n",
    "    '订单ID': [1, 2, 3, 4, 5],\n",
    "    '客户ID': [1, 1, 2, 4, 4],\n",
    "    '销售额': [100, 50, 75, 90, 120]\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b79a9eb4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>邮箱</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Amy</td>\n",
       "      <td>amy@xxx.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Bill</td>\n",
       "      <td>bill@xxx.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Cathy</td>\n",
       "      <td>cat@xxx.com</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Dave</td>\n",
       "      <td>dave@xxx.com</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID     姓名            邮箱\n",
       "0     1    Amy   amy@xxx.com\n",
       "1     2   Bill  bill@xxx.com\n",
       "2     3  Cathy   cat@xxx.com\n",
       "3     4   Dave  dave@xxx.com"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "4767daf4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单ID</th>\n",
       "      <th>客户ID</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单ID  客户ID  销售额\n",
       "0     1     1  100\n",
       "1     2     1   50\n",
       "2     3     2   75\n",
       "3     4     4   90\n",
       "4     5     4  120"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "c24107d3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>邮箱</th>\n",
       "      <th>订单ID</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Amy</td>\n",
       "      <td>amy@xxx.com</td>\n",
       "      <td>1</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Amy</td>\n",
       "      <td>amy@xxx.com</td>\n",
       "      <td>2</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>Bill</td>\n",
       "      <td>bill@xxx.com</td>\n",
       "      <td>3</td>\n",
       "      <td>75</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Dave</td>\n",
       "      <td>dave@xxx.com</td>\n",
       "      <td>4</td>\n",
       "      <td>90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>Dave</td>\n",
       "      <td>dave@xxx.com</td>\n",
       "      <td>5</td>\n",
       "      <td>120</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID    姓名            邮箱  订单ID  销售额\n",
       "0     1   Amy   amy@xxx.com     1  100\n",
       "1     1   Amy   amy@xxx.com     2   50\n",
       "2     2  Bill  bill@xxx.com     3   75\n",
       "3     4  Dave  dave@xxx.com     4   90\n",
       "4     4  Dave  dave@xxx.com     5  120"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据“客户ID”合并customer_df和order_df\n",
    "pd.merge(customer_df, order_df, on='客户ID')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "fedc9c7d",
   "metadata": {},
   "outputs": [],
   "source": [
    "order_df2 = pd.DataFrame({\n",
    "    '订单ID': ['A001', 'A002', 'A003', 'A004'],\n",
    "    '订单日期': ['2000-01-01', '2000-01-02', '2000-01-02', '2000-01-03'],\n",
    "    '客户ID': ['C001', 'C002', 'C001', 'C003'],\n",
    "    '销售额': [100, 200, 150, 300]\n",
    "})\n",
    "\n",
    "customer_df2 = pd.DataFrame({\n",
    "    '客户ID': ['C001', 'C002', 'C003'],\n",
    "    '姓名': ['张三', '李四', '王五'],\n",
    "    '手机号': ['13512345678', '13612345678', '13712345678'],\n",
    "    '订单日期': ['2000-01-01', '2000-01-02', '2000-01-03']\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "c7404f3e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>客户ID</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A001</td>\n",
       "      <td>2000-01-01</td>\n",
       "      <td>C001</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A002</td>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>C002</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A003</td>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>C001</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A004</td>\n",
       "      <td>2000-01-03</td>\n",
       "      <td>C003</td>\n",
       "      <td>300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单ID        订单日期  客户ID  销售额\n",
       "0  A001  2000-01-01  C001  100\n",
       "1  A002  2000-01-02  C002  200\n",
       "2  A003  2000-01-02  C001  150\n",
       "3  A004  2000-01-03  C003  300"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order_df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "3db5bf3f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>手机号</th>\n",
       "      <th>订单日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>C001</td>\n",
       "      <td>张三</td>\n",
       "      <td>13512345678</td>\n",
       "      <td>2000-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>C002</td>\n",
       "      <td>李四</td>\n",
       "      <td>13612345678</td>\n",
       "      <td>2000-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C003</td>\n",
       "      <td>王五</td>\n",
       "      <td>13712345678</td>\n",
       "      <td>2000-01-03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID  姓名          手机号        订单日期\n",
       "0  C001  张三  13512345678  2000-01-01\n",
       "1  C002  李四  13612345678  2000-01-02\n",
       "2  C003  王五  13712345678  2000-01-03"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_df2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "3dcabca9",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>客户ID</th>\n",
       "      <th>销售额</th>\n",
       "      <th>姓名</th>\n",
       "      <th>手机号</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A001</td>\n",
       "      <td>2000-01-01</td>\n",
       "      <td>C001</td>\n",
       "      <td>100</td>\n",
       "      <td>张三</td>\n",
       "      <td>13512345678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A002</td>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>C002</td>\n",
       "      <td>200</td>\n",
       "      <td>李四</td>\n",
       "      <td>13612345678</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A004</td>\n",
       "      <td>2000-01-03</td>\n",
       "      <td>C003</td>\n",
       "      <td>300</td>\n",
       "      <td>王五</td>\n",
       "      <td>13712345678</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单ID        订单日期  客户ID  销售额  姓名          手机号\n",
       "0  A001  2000-01-01  C001  100  张三  13512345678\n",
       "1  A002  2000-01-02  C002  200  李四  13612345678\n",
       "2  A004  2000-01-03  C003  300  王五  13712345678"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据“客户ID”和“订单日期”合并order_df2和customer_df2\n",
    "pd.merge(order_df2, customer_df2, on=[\"客户ID\", \"订单日期\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "1054b837",
   "metadata": {},
   "outputs": [],
   "source": [
    "order_df3 = pd.DataFrame({\n",
    "    '订单ID': ['A001', 'A002', 'A003', 'A004'],\n",
    "    '订单日期': ['2000-01-01', '2000-01-02', '2000-01-02', '2000-01-03'],\n",
    "    '客户编号': ['C001', 'C002', 'C001', 'C003'],\n",
    "    '销售额': [100, 200, 150, 300]\n",
    "})\n",
    "\n",
    "customer_df3 = pd.DataFrame({\n",
    "    '客户ID': ['C001', 'C002', 'C003'],\n",
    "    '姓名': ['张三', '李四', '王五'],\n",
    "    '手机号': ['13512345678', '13612345678', '13712345678'],\n",
    "    '交易日期': ['2000-01-01', '2000-01-02', '2000-01-03']\n",
    "})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "4fb6c4b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>客户编号</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A001</td>\n",
       "      <td>2000-01-01</td>\n",
       "      <td>C001</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A002</td>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>C002</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A003</td>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>C001</td>\n",
       "      <td>150</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>A004</td>\n",
       "      <td>2000-01-03</td>\n",
       "      <td>C003</td>\n",
       "      <td>300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单ID        订单日期  客户编号  销售额\n",
       "0  A001  2000-01-01  C001  100\n",
       "1  A002  2000-01-02  C002  200\n",
       "2  A003  2000-01-02  C001  150\n",
       "3  A004  2000-01-03  C003  300"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order_df3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "fa0e4747",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>手机号</th>\n",
       "      <th>交易日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>C001</td>\n",
       "      <td>张三</td>\n",
       "      <td>13512345678</td>\n",
       "      <td>2000-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>C002</td>\n",
       "      <td>李四</td>\n",
       "      <td>13612345678</td>\n",
       "      <td>2000-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>C003</td>\n",
       "      <td>王五</td>\n",
       "      <td>13712345678</td>\n",
       "      <td>2000-01-03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID  姓名          手机号        交易日期\n",
       "0  C001  张三  13512345678  2000-01-01\n",
       "1  C002  李四  13612345678  2000-01-02\n",
       "2  C003  王五  13712345678  2000-01-03"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_df3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "65680649",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>客户编号</th>\n",
       "      <th>销售额</th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>手机号</th>\n",
       "      <th>交易日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>A001</td>\n",
       "      <td>2000-01-01</td>\n",
       "      <td>C001</td>\n",
       "      <td>100</td>\n",
       "      <td>C001</td>\n",
       "      <td>张三</td>\n",
       "      <td>13512345678</td>\n",
       "      <td>2000-01-01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>A002</td>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>C002</td>\n",
       "      <td>200</td>\n",
       "      <td>C002</td>\n",
       "      <td>李四</td>\n",
       "      <td>13612345678</td>\n",
       "      <td>2000-01-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>A004</td>\n",
       "      <td>2000-01-03</td>\n",
       "      <td>C003</td>\n",
       "      <td>300</td>\n",
       "      <td>C003</td>\n",
       "      <td>王五</td>\n",
       "      <td>13712345678</td>\n",
       "      <td>2000-01-03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单ID        订单日期  客户编号  销售额  客户ID  姓名          手机号        交易日期\n",
       "0  A001  2000-01-01  C001  100  C001  张三  13512345678  2000-01-01\n",
       "1  A002  2000-01-02  C002  200  C002  李四  13612345678  2000-01-02\n",
       "2  A004  2000-01-03  C003  300  C003  王五  13712345678  2000-01-03"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据order_df3的'客户编号'与'customer_df3的'客户ID'，以及order_df3的'订单日期'与'customer_df3的'交易日期'进行合并\n",
    "\n",
    "pd.merge(order_df3, customer_df3, left_on=['客户编号', '订单日期'], right_on=['客户ID', '交易日期'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "be453cd9",
   "metadata": {},
   "outputs": [],
   "source": [
    "df7 = pd.DataFrame({'日期': ['2000-01-01', '2000-01-02', '2000-01-03'],\n",
    "                    '店铺': ['A', 'B', 'C'],\n",
    "                    '销售额': [100, 200, 300]})\n",
    "df8 = pd.DataFrame({'日期': ['2000-01-02', '2000-01-03', '2000-01-04'],\n",
    "                    '店铺': ['B', 'C', 'D'],\n",
    "                    '销售额': [400, 500, 600]})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "971088b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>店铺</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2000-01-01</td>\n",
       "      <td>A</td>\n",
       "      <td>100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>B</td>\n",
       "      <td>200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2000-01-03</td>\n",
       "      <td>C</td>\n",
       "      <td>300</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期 店铺  销售额\n",
       "0  2000-01-01  A  100\n",
       "1  2000-01-02  B  200\n",
       "2  2000-01-03  C  300"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "20f8cb33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>店铺</th>\n",
       "      <th>销售额</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>B</td>\n",
       "      <td>400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2000-01-03</td>\n",
       "      <td>C</td>\n",
       "      <td>500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2000-01-04</td>\n",
       "      <td>D</td>\n",
       "      <td>600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期 店铺  销售额\n",
       "0  2000-01-02  B  400\n",
       "1  2000-01-03  C  500\n",
       "2  2000-01-04  D  600"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "61fdc17f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>店铺</th>\n",
       "      <th>销售额_x</th>\n",
       "      <th>销售额_y</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>B</td>\n",
       "      <td>200</td>\n",
       "      <td>400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2000-01-03</td>\n",
       "      <td>C</td>\n",
       "      <td>300</td>\n",
       "      <td>500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期 店铺  销售额_x  销售额_y\n",
       "0  2000-01-02  B    200    400\n",
       "1  2000-01-03  C    300    500"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据“日期”和“店铺”合并df7和df8\n",
    "pd.merge(df7, df8, on=[\"日期\", \"店铺\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "53e810ec",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>店铺</th>\n",
       "      <th>销售额_df7</th>\n",
       "      <th>销售额_df8</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2000-01-02</td>\n",
       "      <td>B</td>\n",
       "      <td>200</td>\n",
       "      <td>400</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2000-01-03</td>\n",
       "      <td>C</td>\n",
       "      <td>300</td>\n",
       "      <td>500</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           日期 店铺  销售额_df7  销售额_df8\n",
       "0  2000-01-02  B      200      400\n",
       "1  2000-01-03  C      300      500"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据“日期”和“店铺”合并df7和df8，让df7的销售额列后缀为'_df7'，df8的销售额列后缀为'_df8'\n",
    "pd.merge(df7, df8, on=[\"日期\", \"店铺\"], suffixes=['_df7', '_df8'])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f9e38ee2",
   "metadata": {},
   "source": [
    "## 更多合并DataFrame例子"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "0dc9a220",
   "metadata": {},
   "outputs": [],
   "source": [
    "customers_data = {\n",
    "    '客户ID': [1, 2, 3, 4, 5],\n",
    "    '姓名': ['Tom', 'Bob', 'Mary', 'Alice', 'John'],\n",
    "    '年龄': [20, 35, 27, 19, 42]\n",
    "}\n",
    "customer_df4 = pd.DataFrame(customers_data)\n",
    "\n",
    "\n",
    "orders_data = {\n",
    "    '订单ID': [1001, 1002, 1003, 1004, 1005, 1006],\n",
    "    '订单日期': ['2000-03-12', '2000-03-13', '2000-03-13', '2000-03-15', '2000-03-18', '2000-03-21'],\n",
    "    '客户ID': [1, 1, 2, 6, 5, 3],\n",
    "    '产品': ['A', 'B', 'C', 'D', 'E', 'F'],\n",
    "    '数量': [2, 3, 1, 4, 5, 2]\n",
    "}\n",
    "order_df4 = pd.DataFrame(orders_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "4f0065e7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>年龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Bob</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Mary</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Alice</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>John</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID     姓名  年龄\n",
       "0     1    Tom  20\n",
       "1     2    Bob  35\n",
       "2     3   Mary  27\n",
       "3     4  Alice  19\n",
       "4     5   John  42"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "f2194e96",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>客户ID</th>\n",
       "      <th>产品</th>\n",
       "      <th>数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1001</td>\n",
       "      <td>2000-03-12</td>\n",
       "      <td>1</td>\n",
       "      <td>A</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1002</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>1</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1003</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>2</td>\n",
       "      <td>C</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1004</td>\n",
       "      <td>2000-03-15</td>\n",
       "      <td>6</td>\n",
       "      <td>D</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1005</td>\n",
       "      <td>2000-03-18</td>\n",
       "      <td>5</td>\n",
       "      <td>E</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1006</td>\n",
       "      <td>2000-03-21</td>\n",
       "      <td>3</td>\n",
       "      <td>F</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单ID        订单日期  客户ID 产品  数量\n",
       "0  1001  2000-03-12     1  A   2\n",
       "1  1002  2000-03-13     1  B   3\n",
       "2  1003  2000-03-13     2  C   1\n",
       "3  1004  2000-03-15     6  D   4\n",
       "4  1005  2000-03-18     5  E   5\n",
       "5  1006  2000-03-21     3  F   2"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order_df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "9f09adbe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>年龄</th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>产品</th>\n",
       "      <th>数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20</td>\n",
       "      <td>1001</td>\n",
       "      <td>2000-03-12</td>\n",
       "      <td>A</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20</td>\n",
       "      <td>1002</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>Bob</td>\n",
       "      <td>35</td>\n",
       "      <td>1003</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>C</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>Mary</td>\n",
       "      <td>27</td>\n",
       "      <td>1006</td>\n",
       "      <td>2000-03-21</td>\n",
       "      <td>F</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>John</td>\n",
       "      <td>42</td>\n",
       "      <td>1005</td>\n",
       "      <td>2000-03-18</td>\n",
       "      <td>E</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID    姓名  年龄  订单ID        订单日期 产品  数量\n",
       "0     1   Tom  20  1001  2000-03-12  A   2\n",
       "1     1   Tom  20  1002  2000-03-13  B   3\n",
       "2     2   Bob  35  1003  2000-03-13  C   1\n",
       "3     3  Mary  27  1006  2000-03-21  F   2\n",
       "4     5  John  42  1005  2000-03-18  E   5"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# inner合并customer_df4和order_df4\n",
    "pd.merge(customer_df4, order_df4, on='客户ID', how='inner')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "92905a5a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>年龄</th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>产品</th>\n",
       "      <th>数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1001.0</td>\n",
       "      <td>2000-03-12</td>\n",
       "      <td>A</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1002.0</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>B</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>Bob</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1003.0</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>C</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>Mary</td>\n",
       "      <td>27.0</td>\n",
       "      <td>1006.0</td>\n",
       "      <td>2000-03-21</td>\n",
       "      <td>F</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>Alice</td>\n",
       "      <td>19.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>John</td>\n",
       "      <td>42.0</td>\n",
       "      <td>1005.0</td>\n",
       "      <td>2000-03-18</td>\n",
       "      <td>E</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1004.0</td>\n",
       "      <td>2000-03-15</td>\n",
       "      <td>D</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID     姓名    年龄    订单ID        订单日期   产品   数量\n",
       "0     1    Tom  20.0  1001.0  2000-03-12    A  2.0\n",
       "1     1    Tom  20.0  1002.0  2000-03-13    B  3.0\n",
       "2     2    Bob  35.0  1003.0  2000-03-13    C  1.0\n",
       "3     3   Mary  27.0  1006.0  2000-03-21    F  2.0\n",
       "4     4  Alice  19.0     NaN         NaN  NaN  NaN\n",
       "5     5   John  42.0  1005.0  2000-03-18    E  5.0\n",
       "6     6    NaN   NaN  1004.0  2000-03-15    D  4.0"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# outer合并customer_df4和order_df4\n",
    "pd.merge(customer_df4, order_df4, on='客户ID', how='outer')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "e8066c03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>年龄</th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>产品</th>\n",
       "      <th>数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20</td>\n",
       "      <td>1001.0</td>\n",
       "      <td>2000-03-12</td>\n",
       "      <td>A</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20</td>\n",
       "      <td>1002.0</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>B</td>\n",
       "      <td>3.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>Bob</td>\n",
       "      <td>35</td>\n",
       "      <td>1003.0</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>C</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>Mary</td>\n",
       "      <td>27</td>\n",
       "      <td>1006.0</td>\n",
       "      <td>2000-03-21</td>\n",
       "      <td>F</td>\n",
       "      <td>2.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>Alice</td>\n",
       "      <td>19</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>5</td>\n",
       "      <td>John</td>\n",
       "      <td>42</td>\n",
       "      <td>1005.0</td>\n",
       "      <td>2000-03-18</td>\n",
       "      <td>E</td>\n",
       "      <td>5.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID     姓名  年龄    订单ID        订单日期   产品   数量\n",
       "0     1    Tom  20  1001.0  2000-03-12    A  2.0\n",
       "1     1    Tom  20  1002.0  2000-03-13    B  3.0\n",
       "2     2    Bob  35  1003.0  2000-03-13    C  1.0\n",
       "3     3   Mary  27  1006.0  2000-03-21    F  2.0\n",
       "4     4  Alice  19     NaN         NaN  NaN  NaN\n",
       "5     5   John  42  1005.0  2000-03-18    E  5.0"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# left合并customer_df4和order_df4\n",
    "pd.merge(customer_df4, order_df4, on='客户ID', how='left')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "95381815",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>年龄</th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>产品</th>\n",
       "      <th>数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1001</td>\n",
       "      <td>2000-03-12</td>\n",
       "      <td>A</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20.0</td>\n",
       "      <td>1002</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>Bob</td>\n",
       "      <td>35.0</td>\n",
       "      <td>1003</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>C</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1004</td>\n",
       "      <td>2000-03-15</td>\n",
       "      <td>D</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>John</td>\n",
       "      <td>42.0</td>\n",
       "      <td>1005</td>\n",
       "      <td>2000-03-18</td>\n",
       "      <td>E</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>3</td>\n",
       "      <td>Mary</td>\n",
       "      <td>27.0</td>\n",
       "      <td>1006</td>\n",
       "      <td>2000-03-21</td>\n",
       "      <td>F</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID    姓名    年龄  订单ID        订单日期 产品  数量\n",
       "0     1   Tom  20.0  1001  2000-03-12  A   2\n",
       "1     1   Tom  20.0  1002  2000-03-13  B   3\n",
       "2     2   Bob  35.0  1003  2000-03-13  C   1\n",
       "3     6   NaN   NaN  1004  2000-03-15  D   4\n",
       "4     5  John  42.0  1005  2000-03-18  E   5\n",
       "5     3  Mary  27.0  1006  2000-03-21  F   2"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# right合并customer_df4和order_df4\n",
    "pd.merge(customer_df4, order_df4, on='客户ID', how='right')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "96a081f7",
   "metadata": {},
   "source": [
    "## 根据索引合并DataFrame"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "07e55efe",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID</th>\n",
       "      <th>姓名</th>\n",
       "      <th>年龄</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Bob</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Mary</td>\n",
       "      <td>27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Alice</td>\n",
       "      <td>19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>John</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID     姓名  年龄\n",
       "0     1    Tom  20\n",
       "1     2    Bob  35\n",
       "2     3   Mary  27\n",
       "3     4  Alice  19\n",
       "4     5   John  42"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "customer_df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "56df0e6b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>客户ID</th>\n",
       "      <th>产品</th>\n",
       "      <th>数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1001</td>\n",
       "      <td>2000-03-12</td>\n",
       "      <td>1</td>\n",
       "      <td>A</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1002</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>1</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1003</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>2</td>\n",
       "      <td>C</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1004</td>\n",
       "      <td>2000-03-15</td>\n",
       "      <td>6</td>\n",
       "      <td>D</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1005</td>\n",
       "      <td>2000-03-18</td>\n",
       "      <td>5</td>\n",
       "      <td>E</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1006</td>\n",
       "      <td>2000-03-21</td>\n",
       "      <td>3</td>\n",
       "      <td>F</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   订单ID        订单日期  客户ID 产品  数量\n",
       "0  1001  2000-03-12     1  A   2\n",
       "1  1002  2000-03-13     1  B   3\n",
       "2  1003  2000-03-13     2  C   1\n",
       "3  1004  2000-03-15     6  D   4\n",
       "4  1005  2000-03-18     5  E   5\n",
       "5  1006  2000-03-21     3  F   2"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "order_df4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "72604547",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>客户ID_customer</th>\n",
       "      <th>姓名</th>\n",
       "      <th>年龄</th>\n",
       "      <th>订单ID</th>\n",
       "      <th>订单日期</th>\n",
       "      <th>客户ID_order</th>\n",
       "      <th>产品</th>\n",
       "      <th>数量</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Tom</td>\n",
       "      <td>20</td>\n",
       "      <td>1001</td>\n",
       "      <td>2000-03-12</td>\n",
       "      <td>1</td>\n",
       "      <td>A</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>Bob</td>\n",
       "      <td>35</td>\n",
       "      <td>1002</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>1</td>\n",
       "      <td>B</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>Mary</td>\n",
       "      <td>27</td>\n",
       "      <td>1003</td>\n",
       "      <td>2000-03-13</td>\n",
       "      <td>2</td>\n",
       "      <td>C</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>Alice</td>\n",
       "      <td>19</td>\n",
       "      <td>1004</td>\n",
       "      <td>2000-03-15</td>\n",
       "      <td>6</td>\n",
       "      <td>D</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>John</td>\n",
       "      <td>42</td>\n",
       "      <td>1005</td>\n",
       "      <td>2000-03-18</td>\n",
       "      <td>5</td>\n",
       "      <td>E</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   客户ID_customer     姓名  年龄  订单ID        订单日期  客户ID_order 产品  数量\n",
       "0              1    Tom  20  1001  2000-03-12           1  A   2\n",
       "1              2    Bob  35  1002  2000-03-13           1  B   3\n",
       "2              3   Mary  27  1003  2000-03-13           2  C   1\n",
       "3              4  Alice  19  1004  2000-03-15           6  D   4\n",
       "4              5   John  42  1005  2000-03-18           5  E   5"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据索引合并customer_df4和order_df4，列后缀分别为\"_customer\"和\"_order\"\n",
    "customer_df4.join(order_df4, how='inner', lsuffix='_customer', rsuffix='_order')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9bc73d37",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
